<?php

namespace app\ruinuo\design;

use app\common\model\RuinuoApp;
use app\common\model\RuinuoButton;
use app\common\model\RuinuoForm;
use app\common\model\RuinuoLists;
use app\common\model\RuinuoMode;
use app\ruinuo\design\FormLayout as CurdForm;

class Curd
{

    public function FileCode($mode_id)
    {
        $RuinuoApp = new RuinuoApp();
        $RuinuoMode = new RuinuoMode();
        $RuinuoForm = new RuinuoForm();
        $RuinuoLists = new RuinuoLists();
        $mode = $RuinuoMode->where("id='" . $mode_id . "'")->findOrEmpty()->toArray();
        $app = $RuinuoApp->where("id='" . $mode['app_id'] . "'")->findOrEmpty()->toArray();
        $form = $RuinuoForm->where("mode_id='" . $mode_id . "'")->findOrEmpty()->toArray();
        $Lists = $RuinuoLists->where("mode_id='" . $mode_id . "'")->order('sort asc,id asc')->select()->toArray();
        $Config = [
            'app' => $app,
            'mode' => $mode,
            'form' => $form,
            'lists' => $Lists,
        ];
        $this->File($Config);
        $this->ControllerPhp($Config);
        $this->InfoPhp($Config);
        $this->ModePhp($Config);
        $this->ListsPhp($Config);
        $this->LogicPhp($Config);
        $this->FormHtml($Config);
        $this->ListsHtml($Config);
        $this->ConfigJs($Config);
        $this->FormJs($Config);
        $this->ListsJs($Config);
    }

    /*生成配置文件代码*/
    public function InfoPhp($config)
    {
        $CurdForm = new CurdForm();
        $app = $config['app']['num'];
        $controller = $config['mode']['num'];
        $mode = ucfirst(GetCamelize($config['mode']['database']));
        $sub_database = !empty($config['mode']['sub_database']) ? json_decode($config['mode']['sub_database'], true) : [];
        if (!empty($config['flow'])) {
            $sub_database[] = [
                'database' => 'ruinuo_flow_status',
                'alias' => 'flow',
                'type' => '1',
                'sub_field' => 'data_id',
                'key_field' => 'id'
            ];
        }
        $InfoMode = [
            'app_id' => $config['app']['id'],
            'app_num' => $config['app']['num'],
            'app_name' => $config['app']['name'],
            'mode_id' => $config['mode']['id'],
            'mode_num' => $config['mode']['num'],
            'mode_name' => $config['mode']['name'],
            'database' => $config['mode']['database'],
            'sub_database' => $sub_database,
        ];

        $layout = !empty($config['form']['layout']) ? json_decode($config['form']['layout'], true) : [];
        $Form = $CurdForm->GetFormField($layout);

        $newForm = [];
        foreach ($Form as $k => $v) {
            $item = [
                'field' => !empty($v['field']) ? $v['field'] : '',
                'title' => !empty($v['title']) ? $v['title'] : '',
                'value' => isset($v['value']) ? $v['value'] : '',
                'tag' => !empty($v['tag']) ? $v['tag'] : '',
                'only' => !empty($v['only']) ? $v['only'] : 2,
                'required' => !empty($v['required']) ? $v['required'] : 2,
                'verify' => !empty($v['verify']) ? $v['verify'] : '',
            ];
            if (!empty($v['range_field'])) {
                $item['range_field'] = $v['range_field'];
            }
            if (!empty($v['options_num'])) {
                $item['options_num'] = $v['options_num'];
            }
            if (!empty($v['cols'])) {
                $item['cols'] = $v['cols'];
            }

            if (!empty($v['database'])) {
                $item['database'] = $v['database'];
            }
            if (!empty($v['database_field'])) {
                $item['database_field'] = $v['database_field'];
            }

            if (!empty($v['num_rule'])) {
                $item['num_rule'] = $v['num_rule'];
            }

            if ($v['tag'] == 'subtable') {
                $Modes = new RuinuoMode();
                $mode_id = !empty($v['mode_id']) ? $v['mode_id'] : 0;
                $mode_sub_id = !empty($v['mode_sub_id']) ? $v['mode_sub_id'] : 0;
                $base = $Modes->where("id='" . $mode_id . "'")->field("database")->find();
                $database = !empty($base['database']) ? $base['database'] : '';
                $item['database'] = $database;
                $item['mode_sub_id'] = $mode_sub_id;
            }
            $newForm[] = $item;
        }

        $InfoForm = [
            'power_field' => !empty($config['form']['power_field']) ? json_decode($config['form']['power_field'], true) : [],
            'layout' => $newForm,
        ];
        $lists = !empty($config['lists']) ? $config['lists'] : [];
        $InfoLists = [];
        foreach ($lists as $k => $v) {
            $table_cols = !empty($v['table_cols']) ? json_decode($v['table_cols'], true) : [];
            $cols = [];
            foreach ($table_cols as $k2 => $v2) {
                $cols[] = [
                    'field' => !empty($v2['field']) ? $v2['field'] : '',
                    'title' => !empty($v2['title']) ? $v2['title'] : '',
                    'update' => !empty($v2['update']) ? $v2['update'] : '',
                    'options' => !empty($v2['options']) ? $v2['options'] : '',
                    'search' => !empty($v2['search']) ? $v2['search'] : '',
                    'total' => !empty($v2['count']) ? $v2['count'] : 2,
                ];
            }

            if (!empty($config['flow'])) {

                $cols[] = ['title' => '流程状态', 'field' => 'flow__status', 'update' => '', 'options' => 'flow_status', 'search' => 'select', 'total' => ''];
            }


            $InfoLists[] = [
                'name' => $v['name'],
                'num' => $v['num'],
                'page_num' => $v['page_num'],
                'order_raw' => $v['order_raw'],
                'power_field' => !empty($v['power_field']) ? json_decode($v['power_field'], true) : [],
                'power_role' => $v['power_role'],
                'power_department' => $v['power_department'],
                'set_where' => $v['set_where'],
                'table_cols' => $cols,
            ];
        }
        $ListModel = "\$DB=\$Model->alias('a')";
        foreach ($InfoMode['sub_database'] as $k => $v) {
            if ($v['type'] == 1) {
                if ($v['database'] == 'ruinuo_flow_status') {
                    $ListModel .= PHP_EOL . "            ->leftJoin('" . $v['database'] . " " . $v['alias'] . "', 'a." . $v['key_field'] . "= " . $v['alias'] . "." . $v['sub_field'] . " and " . $v['alias'] . ".mode_id=".$config['mode']['id']."')";
                } else {
                    $ListModel .= PHP_EOL . "            ->leftJoin('" . $v['database'] . " " . $v['alias'] . "', 'a." . $v['key_field'] . "= " . $v['alias'] . "." . $v['sub_field'] . "')";
                }

            } else {
                $ListModel .= PHP_EOL . "            ->Join('" . $v['database'] . " " . $v['alias'] . "', 'a." . $v['sub_field'] . "= " . $v['alias'] . "." . $v['key_field'] . "')";
            }
        }
        $ListModel .= ";";

        $path = App()->getBasePath() . "/" . $app . "/config/" . $controller . "/Info.php";
        $str = file_get_contents(App()->getBasePath() . "/ruinuo/codetpl/info.tpl");
        $str = str_replace("<app>", $app, $str);
        $str = str_replace("<controller>", $controller, $str);
        $str = str_replace("<mode>", $mode, $str);
        $str = str_replace("<ListModel>", $ListModel, $str);
        $str = str_replace("<InfoMode>", $this->ChangeArray($InfoMode), $str);
        $str = str_replace("<InfoForm>", $this->ChangeArray($InfoForm), $str);
        $str = str_replace("<InfoLists>", $this->ChangeArray(['lists' => $InfoLists]), $str);
        getCreatetxt($path, $str);
    }

    public function ChangeArray($arr, $enter = '            ')
    {
        $str = '';
        foreach ($arr as $k => $v) {
            if (is_array($v)) {
                if (!empty($v)) {
                    $str .= PHP_EOL . $enter . "'" . $k . "'=>[" . PHP_EOL;
                    foreach ($v as $k2 => $v2) {
                        $str .= "                [" . $this->ChangeArray($v2, '                    ') . PHP_EOL . "                ]," . PHP_EOL;
                    }
                    $str .= "            ]," . PHP_EOL;
                } else {
                    $str .= PHP_EOL . $enter . "'" . $k . "'=>[],";
                }
            } else {
                $str .= PHP_EOL . $enter . "'" . $k . "'=>'" . $v . "',";
            }
        }
        return $str;
    }


    /*生成控制器代码*/
    public function ControllerPhp($config)
    {
        $app = $config['app']['num'];
        $controller = $config['mode']['num'];
        $mode = ucfirst(GetCamelize($config['mode']['database']));
        $path = App()->getBasePath() . "/" . $app . "/controller/" . ucfirst($controller) . ".php";
        if (!file_exists($path)) {
            $str = file_get_contents(App()->getBasePath() . "/ruinuo/codetpl/controller.tpl");
            $str = str_replace("<app>", $app, $str);
            $str = str_replace("<controller>", $controller, $str);
            $str = str_replace("<mode>", $mode, $str);
            $str = str_replace("<ccontroller>", ucfirst($controller), $str);
            getCreatetxt($path, $str);
        }
        $this->SyncInit($config);
        $this->SaveButton($config);
    }

    /*生成模型代码*/
    public function ModePhp($config)
    {
        $mode = ucfirst(GetCamelize($config['mode']['database']));
        $database = $config['mode']['database'];
        $path = App()->getBasePath() . "/common/model/" . $mode . ".php";
        $str = file_get_contents(App()->getBasePath() . "/ruinuo/codetpl/mode.tpl");
        $str = str_replace("<mode>", $mode, $str);
        $str = str_replace("<database>", $database, $str);
        getCreatetxt($path, $str);
    }


    /*生成列表代码*/
    public function ListsPhp($config)
    {
        $app = $config['app']['num'];
        $controller = $config['mode']['num'];
        $database = $config['mode']['database'];
        $mode = ucfirst(GetCamelize($database));
        $path = App()->getBasePath() . "/" . $app . "/config/" . $controller . "/Lists.php";
        if (!file_exists($path)) {
            $str = file_get_contents(App()->getBasePath() . "/ruinuo/codetpl/lists.tpl");
            $str = str_replace("<app>", $app, $str);
            $str = str_replace("<controller>", $controller, $str);
            $str = str_replace("<mode>", $mode, $str);
            getCreatetxt($path, $str);
        }
    }

    /*生成增删改查代码*/
    public function LogicPhp($config)
    {
        $CurdForm = new CurdForm();
        $app = $config['app']['num'];
        $controller = $config['mode']['num'];
        $mode = ucfirst(GetCamelize($config['mode']['database']));
        $path = App()->getBasePath() . "/" . $app . "/config/" . $controller . "/Logic.php";
        if (!file_exists($path)) {
            $str = file_get_contents(App()->getBasePath() . "/ruinuo/codetpl/logic.tpl");
            $str = str_replace("<app>", $app, $str);
            $str = str_replace("<controller>", $controller, $str);
            $str = str_replace("<mode>", $mode, $str);
            getCreatetxt($path, $str);
        }
    }


    /*生成表单HTML代码*/
    public function FormHtml($config)
    {
        $CurdForm = new CurdForm();
        $app = $config['app']['num'];
        $controller = $config['mode']['num'];
        $title = $config['mode']['name'];
        $layout = !empty($config['form']['layout']) ? json_decode($config['form']['layout'], true) : [];
        $html = $CurdForm->GetForm($layout);
        $bind = $CurdForm->GetJs($layout);
        $path = App()->getBasePath() . "/common/template/" . $app . "/" . $controller . "/form.html";
        $str = file_get_contents(App()->getBasePath() . "/ruinuo/codetpl/form.html");
        $str = str_replace("<app>", $app, $str);
        $str = str_replace("<controller>", $controller, $str);
        $str = str_replace("<-title>", $title, $str);
        $str = str_replace("<html>", $html, $str);
        $str = str_replace("let bind='';", $bind, $str);
        getCreatetxt($path, $str);
    }

    /*生成列表HTML代码*/
    public function ListsHtml($config)
    {
        $app = $config['app']['num'];
        $controller = $config['mode']['num'];
        $title = $config['mode']['name'];
        $path = App()->getBasePath() . "/common/template/" . $app . "/" . $controller . "/lists.html";
        $str = file_get_contents(App()->getBasePath() . "/ruinuo/codetpl/lists.html");
        $str = str_replace("<app>", $app, $str);
        $str = str_replace("<controller>", $controller, $str);
        $str = str_replace("<-title>", $title, $str);
        $table_tpl = '';
        $Lists = !empty($config['lists']) ? $config['lists'] : [];
        foreach ($Lists as $k => $v) {
            $cols = !empty($v['table_cols']) ? json_decode($v['table_cols'], true) : [];
            foreach ($cols as $kk => $vv) {
                if (!empty($vv['tpl'])) {
                    $table_tpl .= '<script type="text/html" id="tpl_' . $vv['id'] . '">' . PHP_EOL;
                    $table_tpl .= $vv['tpl'] . PHP_EOL;
                    $table_tpl .= '</script>' . PHP_EOL;
                }
            }
        }
        $str = str_replace("<table_tpl>", $table_tpl, $str);
        getCreatetxt($path, $str);
    }

    /*生成配置JS代码*/
    public function ConfigJs($config)
    {

        $RuinuoButton = new RuinuoButton();
        $app = $config['app']['num'];
        $controller = $config['mode']['num'];
        $label_width = !empty($config['form']['label_width']) ? $config['form']['label_width'] : '';
        $form_label = !empty($config['form']['form_label']) ? $config['form']['form_label'] : 'form_right';
        $Lists = !empty($config['lists']) ? $config['lists'] : [];
        $path = 'static/js/' . $app . '/' . $controller . '/config.js';
        $str = file_get_contents(App()->getBasePath() . "/ruinuo/codetpl/config.js");
        $str = str_replace("<app>", $app, $str);
        $str = str_replace("<controller>", $controller, $str);
        $str = str_replace("<label_width>", $label_width, $str);
        $str = str_replace("<form_label>", $form_label, $str);
        $tableConfig = [];
        foreach ($Lists as $k => $v) {
            $page = !empty($v['page_num']) ? true : false;
            $datetime = [];
            $like = '';
            $cols = !empty($v['table_cols']) ? json_decode($v['table_cols'], true) : [];
            foreach ($cols as $kk => $vv) {
                $search = !empty($vv['search']) ? $vv['search'] : '';
                if (!empty($vv['hide'])) {
                    if ($vv['hide'] != 1) {
                        unset($cols[$kk]['hide']);
                    }
                }

                switch ($search) {
                    case "datetime":
                        $datetime[] = ['value' => $vv['field'], 'label' => $vv['title']];
                        break;
                    case "like":
                        $like .= $vv['title'] . '|';
                        break;
                }
                $width = !empty($vv['width']) ? $vv['width'] : 90;
                $cols[$kk]['minWidth'] = $width;
                if (!empty($vv['tpl'])) {
                    $cols[$kk]['tpl'] = "#tpl_" . $vv['id'];
                }
                unset($cols[$kk]['width']);
                unset($cols[$kk]['id']);
            }

            if (!empty($config['flow'])) {

                $cols[] = ['title' => '流程状态', 'field' => 'flow__status', 'minWidth' => 90,'options' => 'flow_status', 'search' => 'select'];
            }




            $searchs = [];
            if (!empty($datetime)) {
                $searchs[] = [
                    'title' => '时间搜索',
                    'field' => 'search_time_field',
                    'width' => '120px',
                    'hide_label' => 1,
                    'tag' => 'select',
                    'value' => '',
                    'no_value' => 1,
                    'data' => [
                        'rows' => $datetime
                    ]
                ];
                $searchs[] = [
                    'title' => '选择日期',
                    'field' => 'search_time_field_val',
                    'placeholder' => '请选择日期检索',
                    'width' => '360px',
                    'hide_label' => 1,
                    'tag' => 'datetime',
                    'value' => '',
                    'range' => '至',
                    'date_cat' => 'datetime'
                ];
            }
            if ($like) {
                $searchs[] = [
                    'title' => '关键词',
                    'field' => 'keyword',
                    'placeholder' => rtrim($like, '|'),
                    'width' => '280px',
                    'hide_label' => 1,
                    'tag' => 'input',
                    'value' => '',
                    'group_prefix' => '关键词',
                ];
            }
            $urls = [
                'title' => '',
                'list' => '/common/options/leftlists/?num=' . $v['left_options'],
                'add' => '',
                'edit' => '',
                'delete' => '',
                'width' => '',
                'height' => '',
            ];
            if ($v['left_type'] == 2 && $v['is_left'] == 1) {
                $findButton = $RuinuoButton->where("mode_id='" . $v['left_mode'] . "' and action='add'")->field('width,height,app_num,mode_num')->findOrEmpty()->toArray();
                if (!empty($findButton)) {
                    $urls = [
                        'list' => "/" . $findButton['app_num'] . "/" . $findButton['mode_num'] . "/lists/",
                        'add' => "/" . $findButton['app_num'] . "/" . $findButton['mode_num'] . "/add/",
                        'edit' => "/" . $findButton['app_num'] . "/" . $findButton['mode_num'] . "/edit/",
                        'delete' => "/" . $findButton['app_num'] . "/" . $findButton['mode_num'] . "/delete/",
                        'width' => !empty($findButton['width']) ? $findButton['width'] : 0,
                        'height' => !empty($findButton['height']) ? $findButton['height'] : 0,
                    ];
                }
            }

            $tableConfig[] = [
                'title' => $v['name'],
                'code' => $v['num'],
                'num' => 0,
                'on' => false,
                'url' => '/' . $app . '/' . $controller . '/tabs/',
                'left' => [
                    'status' => !empty($v['is_left']) ? $v['is_left'] : 2,
                    'title' => $v['left_title'],
                    'options_id' => $v['left_options'],
                    'key_field' => $v['left_key_field'],
                    'show_field' => $v['left_show_field'],
                    'field' => $v['left_field'],
                    'type' => $v['left_type'],
                    'url' => $urls
                ],
                'source' => [],
                'header' => [
                    'menu' => [],
                    'total' => [],
                    'button' => [],
                    'search' => $searchs,
                ],
                'table' => [
                    'style' => $v['style'],
                    'parent_id' => $v['tree_field'] ?: 'parent_id',
                    'parent_name' => $v['tree_show_field'] ?: 'title',
                    'limit' => $v['page_num'],
                    'page' => $page,
                    'elem' => 'datatable',
                    'height' => 'full-130',
                    'update' => '/' . $app . '/' . $controller . '/upfield/',
                    'url' => '/' . $app . '/' . $controller . '/lists/',
                    'cols' => $cols,
                    'button' => [],
                ],
            ];
        }
        $table_config = json_encode($tableConfig, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
        $table_config = str_replace('\\', '', $table_config);
        $str = str_replace("'<table_config>'", $table_config, $str);
        $CurdForm = new CurdForm();
        $layout = !empty($config['form']['layout']) ? json_decode($config['form']['layout'], true) : [];
        $fields = $CurdForm->GetFormField($layout);
        $onclick = [];
        foreach ($fields as $k => $v) {
            $event_val = !empty($v['event_val']) ? $v['event_val'] : [];
            $gongshi_txt = !empty($v['gongshi_txt']) ? $v['gongshi_txt'] : '';
            foreach ($event_val as $k2 => $v2) {
                $v2['field'] = $v['field'];
                $v2['tag'] = $v['tag'];
                $onclick[] = $v2;
            }
            if ($gongshi_txt) {
                $onclick[] = [
                    'field' => $v['field'],
                    'tag' => $v['tag'],
                    'gongshi_txt' => $gongshi_txt,
                ];
            }
        }
        $onclick = json_encode($onclick, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
        $str = str_replace("'<onclick>'", $onclick, $str);
        getCreatetxt($path, $str);
    }

    /*生成表单JS代码*/
    public function FormJs($config)
    {
        $app = $config['app']['num'];
        $controller = $config['mode']['num'];
        $path = 'static/js/' . $app . '/' . $controller . '/form.js';
        if (!file_exists($path)) {
            $str = file_get_contents(App()->getBasePath() . "/ruinuo/codetpl/form.js");
            getCreatetxt($path, $str);
        }
    }

    /*生成列表JS代码*/
    public function ListsJs($config)
    {
        $app = $config['app']['num'];
        $controller = $config['mode']['num'];
        $path = 'static/js/' . $app . '/' . $controller . '/lists.js';
        if (!file_exists($path)) {
            $str = file_get_contents(App()->getBasePath() . "/ruinuo/codetpl/lists.js");
            getCreatetxt($path, $str);
        }
    }

    public function File($config)
    {
        $app = $config['app']['num'];
        $controller = $config['mode']['num'];
        $file = [
            App()->getBasePath() . $app . '/',
            App()->getBasePath() . $app . '/controller/',
            App()->getBasePath() . $app . '/config/',
            App()->getBasePath() . $app . '/config/' . $controller . '/',
            App()->getBasePath() . 'common/template/' . $app . '/' . $controller . '/',
            'static/js/' . $app . '/',
            'static/js/' . $app . '/' . $controller . '/',
        ];
        foreach ($file as $k => $v) {
            if (!file_exists($v)) {
                mkdir($v, 0777, true);
            }
        }
    }

    public function SyncInit($config)
    {

        $RuinuoLists = new RuinuoLists();
        $RuinuoForm = new RuinuoForm();
        if (empty($config['form'])) {
            $upData = [
                'mode_id' => $config['mode']['id'],
            ];
            $RuinuoForm->save($upData);
        }
        $Lists = $config['lists'];
        if (empty($Lists)) {
            $cols = [
                ['field' => 'id', 'title' => '主键', 'width' => 70, 'id' => 'm_' . time()]
            ];
            $upData = [
                'mode_id' => $config['mode']['id'],
                'name' => '全部',
                'num' => 'm_' . time(),
                'sort' => 1,
                'order_raw' => 'id desc',
                'style' => 1,
                'page_num' => 30,
                'is_left' => 2,
                'table_cols' => json_encode($cols, JSON_UNESCAPED_UNICODE)
            ];
            $RuinuoLists->save($upData);
        }
    }

    public function SaveButton($config)
    {
        $RuinuoButton = new RuinuoButton();
        $mode_id = $config['mode']['id'];
        $app_num = $config['app']['num'];
        $mode_num = $config['mode']['num'];
        $Form = $config['form'];
        $width = !empty($Form['width']) ? $Form['width'] : 0;
        $height = !empty($Form['height']) ? $Form['height'] : 0;
        $url = "/" . $app_num . "/" . $mode_num . "/";
        $arr = [
            ['node' => 1, 'title' => '新增', 'action' => 'add'],
            ['node' => 1, 'title' => '修改', 'action' => 'edit'],
            ['node' => 1, 'title' => '删除', 'action' => 'delete'],
            ['node' => 1, 'title' => '批量删除', 'action' => 'alldelete'],
            ['node' => 1, 'title' => '查看', 'action' => 'detail'],
            ['node' => 1, 'title' => '导入', 'action' => 'inexcel'],
            ['node' => 1, 'title' => '导出', 'action' => 'outexcel'],
            ['node' => 2, 'title' => '列表', 'action' => 'lists'],
        ];
        $allBtn = [];
        foreach ($arr as $k => $v) {
            $Button = $RuinuoButton->where("mode_id='" . $mode_id . "' and action='" . $v['action'] . "' and is_admin=1")->count();
            if (empty($Button)) {
                $upData = $v;
                $upData['mode_id'] = $mode_id;
                $upData['app_num'] = $app_num;
                $upData['mode_num'] = $mode_num;
                $upData['is_admin'] = 1;
                $upData['sort'] = $k + 1;
                switch ($v['action']) {
                    case "add":
                        $upData['icon'] = 'icon-add-bold';
                        $upData['position'] = 1;
                        $upData['type'] = 'window';
                        $upData['btn_class'] = 'btn_theme_1';
                        $upData['width'] = $width;
                        $upData['height'] = $height;
                        break;
                    case "edit":
                        $upData['icon'] = 'icon-edit';
                        $upData['position'] = 2;
                        $upData['type'] = 'window';
                        $upData['btn_class'] = 'btn_theme_1';
                        $upData['query'] = 'id={id}';
                        $upData['width'] = $width;
                        $upData['height'] = $height;
                        break;
                    case "detail":
                        $upData['icon'] = 'icon-search';
                        $upData['position'] = 2;
                        $upData['type'] = 'window';
                        $upData['btn_class'] = 'btn_theme_4';
                        $upData['query'] = 'id={id}';
                        break;
                    case "delete":
                        $upData['icon'] = 'icon-ashbin';
                        $upData['position'] = 2;
                        $upData['type'] = 'ajax';
                        $upData['btn_class'] = 'btn_theme_2';
                        $upData['query'] = 'id={id}';
                        break;
                    case "alldelete":
                        $upData['icon'] = 'icon-ashbin';
                        $upData['position'] = 1;
                        $upData['type'] = 'ajax';
                        $upData['btn_class'] = 'btn_theme_2';
                        $upData['query'] = 'ids={id}';
                        $upData['is_choose'] = 1;
                        $upData['status'] = 2;
                        break;
                    case "inexcel":
                        $upData['icon'] = 'icon-rising1';
                        $upData['position'] = 1;
                        $upData['btn_class'] = 'btn_theme_0';
                        $upData['type'] = 'window';
                        $upData['status'] = 2;
                        break;
                    case "outexcel":
                        $upData['icon'] = 'icon-sign-out';
                        $upData['position'] = 1;
                        $upData['type'] = 'ajax';
                        $upData['btn_class'] = 'btn_theme_0';
                        $upData['status'] = 2;
                        break;
                }
                $allBtn[] = $upData;
            }
        }
        if ($allBtn) {
            $RuinuoButton->saveAll($allBtn);
        }
    }

}